#ifdef __cplusplus
    #include <cstdlib>
#else
    #include <stdlib.h>
#endif

#include <SDL/SDL.h>

int main ( int argc, char** argv )
 {

SDL_Surface *screen; //This pointer will reference the backbuffer
SDL_Surface *image; //This pointer will reference our bitmap sprite
SDL_Surface *temp;//This pointer will temporarily reference our bitmap  sprite
SDL_Rect src, dest, pos1, pos2, pos3, pos4, pos5,pos6,pos7,pos8,pos9,pos10,pos11;//These rectangles will describe the source and destination regions of our blit
SDL_Event event;
SDL_Surface *pnum1;
SDL_Surface *num1;
SDL_Surface *pnum2;
SDL_Surface *num2;
SDL_Surface *pnum3;
SDL_Surface *num3;
SDL_Surface *pnum4;
SDL_Surface *num4;
SDL_Surface *pnum5;
SDL_Surface *num5;
SDL_Surface *pnum6;
SDL_Surface *num6;
SDL_Surface *pnum7;
SDL_Surface *num7;
SDL_Surface *pnum8;
SDL_Surface *num8;
SDL_Surface *pnum9;
SDL_Surface *num9;
SDL_Surface *pnum10;
SDL_Surface *num10;
SDL_Surface *pnum11;
SDL_Surface *num11;
int done = 1;
int b=0;

if (SDL_Init(SDL_INIT_VIDEO) != 0) {
printf("Unable to initialize SDL: %s\n", SDL_GetError());
return 1;
}
//Set the video mode to fullscreen 640x480 with 16bit colour and double- buffering
screen = SDL_SetVideoMode(653,489, 32, SDL_HWSURFACE | SDL_DOUBLEBUF);
if (screen == NULL) {
printf("Unable to set video mode: %s\n", SDL_GetError());
return 1;
}
//Load the bitmap into a temporary surface, and check for success
temp = SDL_LoadBMP("img/photo1.bmp");
if (temp == NULL) {
printf("Unable to load bitmap: %s\n", SDL_GetError());
return 1;
}
//Convert the surface to the appropriate display format
image = SDL_DisplayFormat(temp);

pnum1 = SDL_LoadBMP("img/photo2.bmp");
num1 = SDL_DisplayFormat(pnum1);
SDL_FreeSurface(pnum1);

pnum2 = SDL_LoadBMP("img/photo3.bmp");
num2 = SDL_DisplayFormat(pnum2);
SDL_FreeSurface(pnum2);

pnum3 = SDL_LoadBMP("img/photo4.bmp");
num3 = SDL_DisplayFormat(pnum3);
SDL_FreeSurface(pnum3);

pnum4 = SDL_LoadBMP("img/photo5.bmp");
num4 = SDL_DisplayFormat(pnum4);
SDL_FreeSurface(pnum4);




//Release the temporary surface
SDL_FreeSurface(temp);
//Construct the source rectangle for our blit
src.x = 0;
src.y = 0;
src.w = image->w; //Use image->w to display the entire width of the image
src.h = image->h; //Use image->h to display the entire height of the image
//Construct the destination rectangle for our blit
dest.x = 0;//Display the image at the (X,Y) coordinates (100,100)
dest.y = 0;
dest.w = image->w;
dest.h = image->h;


pos1.x =180;
pos1.y = 40;
pos1.w = num1->w;
pos1.h = num1->h;

pos2.x = 180;
pos2.y = 100;
pos2.w = num1->w;
pos2.h = num1->h;

pos3.x = 180;
pos3.y = 160;
pos3.w = num1->w;
pos3.h = num1->h;

pos4.x = 160;
pos4.y = 220;
pos4.w = num1->w;
pos4.h = num1->h;








SDL_SetColorKey(num1, SDL_SRCCOLORKEY, SDL_MapRGB(num1->format, 255, 255, 255));
SDL_SetColorKey(num2, SDL_SRCCOLORKEY, SDL_MapRGB(num2->format, 255, 255, 255));
SDL_SetColorKey(num3, SDL_SRCCOLORKEY, SDL_MapRGB(num3->format, 255, 255, 255));
SDL_SetColorKey(num4, SDL_SRCCOLORKEY, SDL_MapRGB(num4->format, 255, 255, 255));



while(done)
{
    //Blit the image to the backbuffer
    SDL_BlitSurface(image, &src, screen, &dest);
    SDL_BlitSurface(num1, NULL, screen, &pos1);
    SDL_BlitSurface(num2, NULL, screen, &pos2);
    SDL_BlitSurface(num3, NULL, screen, &pos3);
    SDL_BlitSurface(num4, NULL, screen, &pos4);
    SDL_Flip(screen);

   SDL_WaitEvent(&event);

    // check for messages
        switch (event.type)
        {
        // exit if the window is closed
        case SDL_QUIT:
        {done = 0;
        break;}
        // check for keypresses

        case  SDL_MOUSEBUTTONDOWN:
        {
        if((event.motion.x>170)&&(event.motion.x<240)&&(event.motion.y<80)&&(event.motion.y>40)){b=1;SDL_SetColorKey(num2, SDL_SRCCOLORKEY, SDL_MapRGB(num2->format, 0, 0, 255));
}

       if((event.motion.x<220)&&(event.motion.x>140)&&(event.motion.y>200)&&(event.motion.y<400)&&(b==1)) {
pnum5 = SDL_LoadBMP("img/photo6.bmp");
num5 = SDL_DisplayFormat(pnum5);
SDL_FreeSurface(pnum5);
pos5.x = 0;
pos5.y = 0;
pos5.w = num5->w;
pos5.h = num5->h;
SDL_BlitSurface(num5,NULL,screen,&pos5);

pnum6 = SDL_LoadBMP("img/photo7.bmp");
num6 = SDL_DisplayFormat(pnum6);
SDL_FreeSurface(pnum6);
pos6.x = 10;
pos6.y = 400;
pos6.w = num6->w;
pos6.h = num6->h;
SDL_BlitSurface(num6,NULL,screen,&pos6);

pnum7 = SDL_LoadBMP("img/photo8.bmp");
num7 = SDL_DisplayFormat(pnum7);
SDL_FreeSurface(pnum7);
pos7.x = 10;
pos7.y = 300;
pos7.w = num7->w;
pos7.h = num7->h;
SDL_BlitSurface(num7,NULL,screen,&pos7);

pnum8 = SDL_LoadBMP("img/photo9.bmp");
num8 = SDL_DisplayFormat(pnum8);
SDL_FreeSurface(pnum8);
pos8.x = 10;
pos8.y = 200;
pos8.w = num8->w;
pos8.h = num8->h;
SDL_BlitSurface(num8,NULL,screen,&pos8);

pnum9 = SDL_LoadBMP("img/photo10.bmp");
num9 = SDL_DisplayFormat(pnum9);
SDL_FreeSurface(pnum9);
pos9.x = 10;
pos9.y = 100;
pos9.w = num9->w;
pos9.h = num9->h;
SDL_BlitSurface(num9,NULL,screen,&pos9);

pnum10 = SDL_LoadBMP("img/photo11.bmp");
num10 = SDL_DisplayFormat(pnum10);
SDL_FreeSurface(pnum10);
pos10.x = 10;
pos10.y = 00;
pos10.w = num10->w;
pos10.h = num10->h;
SDL_BlitSurface(num10,NULL,screen,&pos10);

pnum11 = SDL_LoadBMP("img/photo12.bmp");
num11 = SDL_DisplayFormat(pnum11);
SDL_FreeSurface(pnum11);
pos11.x = 200;
pos11.y =380;
pos11.w = num11->w;
pos11.h = num11->h;
SDL_BlitSurface(num11,NULL,screen,&pos11);
SDL_FreeSurface(image);
SDL_FreeSurface(num1);
SDL_FreeSurface(num2);
SDL_FreeSurface(num3);
SDL_FreeSurface(num4);
SDL_Flip(screen);
getchar();}

break;}



   case SDL_KEYDOWN:
        {



        // exit if ESCAPE is pressed
        if (event.key.keysym.sym == SDLK_ESCAPE)
       {done=0;


        break;}

        } // end switch
     // end of message processing
}

}
SDL_FreeSurface(image);
return 0; //Return success!

}
